package org.inspiration.dudu.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.inspiration.dudu.user.model.dto.FavoriteFolderDTO;
import org.inspiration.dudu.user.model.entity.FavoriteFolderEntity;

import java.util.List;

@Mapper
public interface FavoriteFolderMapper extends BaseMapper<FavoriteFolderEntity> {
    /**
     * 创建新的收藏夹
     *
     * @param favoriteFolderEntity 收藏夹实体
     */
    @Insert("insert into favorite_folder(user_id, folder_name, created_at) VALUES (#{userId}, #{folderName}, #{createdAt})")
    void createFavoriteFolder(FavoriteFolderEntity favoriteFolderEntity);

    /**
     * 删除指定用户的收藏夹
     *
     * @param favoriteFolderDTO 收藏夹数据传输对象
     */
    @Delete("delete from favorite_folder where user_id = #{userId} and folder_name = #{folderName}")
    void deleteFavoriteFolder(FavoriteFolderDTO favoriteFolderDTO);

    /**
     * 根据用户ID获取所有收藏夹
     *
     * @param userId 用户ID
     * @return 收藏夹实体列表
     */
    @Select("select * from favorite_folder where user_id = #{userId}")
    List<FavoriteFolderEntity> getAllFavoriteFoldersByUserId(Long userId);

    /**
     * 增加收藏夹中的内容数量
     *
     * @param folderId 收藏夹ID
     */
    @Update("update favorite_folder set content_count = content_count + 1 where id = #{folderId}")
    void increaseContentCount(Long folderId);

    /**
     * 减少收藏夹中的内容数量
     *
     * @param folderId 收藏夹ID
     */
    @Update("update favorite_folder set content_count = content_count - 1 where id = #{folderId}")
    void decreaseContentCount(Long folderId);
}
